<template>
  <div>
    <!-- 头部 --start-->
    <div class="nav">
      <p>
        <span>.</span>
        新增订单
      </p>

      <div id="nav_go5">
        <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="revert()">返回</el-button>
      </div>
    </div>
    <!-- 头部 --end-->

    <!-- 合同信息 --start-->
    <div class="conter_box1">
      <p>
        <em>1</em> 合同信息
      </p>
      <ul>
        <li>
          <span>订单编号</span>
          <el-input placeholder="请输入订单编号" v-model="orderno" style="width:70%"></el-input>
        </li>
        <li>
          <span>订单类型</span>
          <el-select v-model="ordtype" placeholder="请选择订单类型" style="width:70%">
            <el-option
              v-for="item in ordtypevalue"
              :key="item.key"
              :label="item.value"
              :value="item.value"
            ></el-option>
          </el-select>
        </li>
        <li>
          <span>企业名称</span>
          <el-input placeholder="请输入企业名称" v-model="compony" style="width:70%"></el-input>
        </li>

        <li>
          <span>接单日期</span>
          <el-date-picker
            v-model="getorderdate"
            type="date"
            placeholder="请选择接单日期"
            style="width:70%"
          ></el-date-picker>
        </li>
        <li>
          <span>交货日期</span>
          <el-date-picker
            v-model="deliverydate"
            type="date"
            placeholder="请选择交货日期"
            style="width:70%"
          ></el-date-picker>
        </li>
        <li>
          <span>签单人员</span>
          <el-input placeholder="请输入签单人员" v-model="writer" style="width:70%"></el-input>
        </li>
      </ul>
    </div>
    <!-- 合同信息 --end-->

    <!-- 产品信息 --start-->
    <div class="conter_box3">
      <p>
        <em>2</em> 产品信息
      </p>
      <template>
        <el-table :data="tableData" style="width: 100%" max-height="200px">
          <el-table-column type="index" label="序号" align="center"></el-table-column>
          <el-table-column label="产品代码" align="center">
            <template slot-scope="scope">
              <el-select v-model="scope.row.procode" style="width:100%">
                <el-option
                  v-for="item in procodevalue"
                  :key="item.key"
                  :label="item.value"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="产品名称" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.proname"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="单位" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.unit"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="数量" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.number"></el-input>
            </template>
          </el-table-column>
          <el-table-column label="交期" align="center" width="150">
            <template slot-scope="scope">
              <el-date-picker v-model="scope.row.deliverydate" type="date" style="width:100%"></el-date-picker>
            </template>
          </el-table-column>
          <el-table-column label="产品类型" align="center">
            <template slot-scope="scope">
              <el-select v-model="scope.row.protype" style="width:100%">
                <el-option
                  v-for="item in protypevalue"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="备注" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" @focus="add4()"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <!-- 产品信息 --end-->

    <!-- 付款信息 --start-->
    <div class="conter_box4">
      <p>
        <em>3</em> 付款信息
      </p>
      <ul>
        <li>
          <span>订单金额</span>
          <el-input placeholder="请输入订单金额" v-model="hemoney" style="width:70%"></el-input>
        </li>
        <li>
          <span>付款方式</span>
          <el-select v-model="paystyle" style="width:70%" @change="fkfs" placeholder="请选择付款方式">
            <el-option
              v-for="item in fukuanstylevalue"
              :key="item.key"
              :label="item.value"
              :value="item.value"
            ></el-option>
          </el-select>
        </li>
        <li v-if="yj==true">
          <span>设置天数</span>
          <el-select style="width:70%" v-model="daycount" @change="fkfs" placeholder="请选择付款方式">
            <el-option
              v-for="item in daysvalue"
              :key="item.key"
              :label="item.value"
              :value="item.value"
            ></el-option>
          </el-select>
        </li>
        <li>
          <span>支付方式</span>
          <el-cascader
            style="width:70%"
            v-model="zhifustyle"
            :options="options"
            :props="{ expandTrigger: 'hover' }"
            @change="handleChange"
          ></el-cascader>
        </li>
        <li v-if="bz==true">
          <span>备注</span>
          <el-input placeholder="请输入备注" v-model="remark" style="width:70%"></el-input>
        </li>
        <li v-if="fq==true">
          <p>定金</p>
          <span>付款时间</span>
          <el-date-picker
            v-model="djfkdate"
            type="date"
            placeholder="请输入付款时间"
            style="width:70%"
            @change="djfkdatefn()"
          ></el-date-picker>
        </li>
        <li v-if="fq==true">
          <p></p>
          <span>付款比例</span>
          <el-input placeholder="请输入付款比例" v-model="djfkratio" style="width:70%"></el-input>
        </li>
        <li v-if="fq==true">
          <p></p>
          <span>付款金额</span>
          <el-input placeholder="请输入付款金额" v-model="djfkmoney" style="width:70%"></el-input>
        </li>
        <li v-if="fq==true">
          <p>尾款</p>
          <span>付款时间</span>
          <el-date-picker
            v-model="wkfkdate"
            type="date"
            placeholder="请输入付款时间"
            style="width:70%"
            @change="wkfkdatefn()"
          ></el-date-picker>
        </li>
        <li v-if="fq==true">
          <p></p>
          <span>付款比例</span>
          <el-input placeholder="请输入付款比例" v-model="wkfkratio" style="width:70%"></el-input>
        </li>
        <li v-if="fq==true">
          <p></p>
          <span>付款金额</span>
          <el-input placeholder="请输入付款金额" v-model="wkfkmoney" style="width:70%"></el-input>
        </li>
      </ul>
    </div>
    <!-- 付款信息 --end-->

    <!-- 附件上传 --start-->
    <div id="conter_box5">
      <p>
        <em>4</em> 合同上传
      </p>
      <ul>
        <li>
          <el-upload
            class="avatar-uploader"
            action="/apis/PublicAPI.asmx/UpImg"
            :show-file-list="false"
            :on-success="handleAvatarSuccess"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrls" :src="imageUrls" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <span>订单导入</span>
        </li>
        <li>
          <el-upload
            class="avatar-uploader"
            action="/apis/PublicAPI.asmx/UpImg"
            :show-file-list="false"
            :on-success="handleAvatarSuccess1"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrls1" :src="imageUrls1" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <span>图纸导入</span>
        </li>
        <li>
          <el-upload
            class="avatar-uploader"
            action="/apis/PublicAPI.asmx/UpImg"
            :show-file-list="false"
            :on-success="handleAvatarSuccess2"
            :before-upload="beforeAvatarUpload"
          >
            <img v-if="imageUrls2" :src="imageUrls2" class="avatar" />
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
          <span>其他导入</span>
        </li>
      </ul>
    </div>
    <!-- 附件上传 --end-->

    <!-- 底部按钮 --start-->
    <div class="bottom">
      <p>
        制表人员
        <el-input style="width:70%" v-model="makeman"></el-input>
      </p>
      <el-button type="primary" size="medium" @click="addordre()">确定</el-button>
      <el-button type="info" size="medium" @click="revert()">返回</el-button>
    </div>
    <!-- 底部按钮 --end-->
  </div>
</template>
<script>
import axios from "axios";
export default {
  data() {
    return {
      imageUrl: "",
      imageUrls: "",
      imageUrl1: "",
      imageUrls1: "",
      imageUrl2: "",
      imageUrls2: "",

      active: 0,
      state1: "",
      state2: "",
      dialogVisible: false,
      tableData: [{}],
      tableData1: [{}],
      tableData2: [{}],
      tableData3: [{}],
      //合同信息
      orderno: "",
      ordtype: "",
      compony: "",
      getorderdate: "",
      deliverydate: "",
      writer: "",

      //付款信息
      //付款信息
      hemoney: "",
      paystyle: "",
      zhifustyle: "",
      //定金
      djfkdate: "",
      djfkratio: "",
      djfkmoney: "",
      //尾款
      wkfkdate: "",
      wkfkratio: "",
      wkfkmoney: "",
      daycount: "", //设置天数
      remark: "", //备注
      makeman: "",
      ordtypevalue: [],
      protypevalue: [
        { value: "1", label: "货箱" },
        { value: "2", label: "发仓" }
      ],
      procodevalue: [],
            fukuanstylevalue: [
        { key: 1, value: "全款" },
        { key: 2, value: "分期" },
        { key: 3, value: "特殊" },
        { key: 4, value: "月结" }
      ],
      daysvalue: [
        { key: 1, value: "30" },
        { key: 2, value: "60" },
        { key: 3, value: "90" },
        { key: 4, value: "120" }
      ],
      options: [
        {
          value: "现金",
          label: "现金"
        },
        {
          value: "承兑汇票",
          label: "承兑汇票",
          children: [
            {
              value: "电子",
              label: "电子"
            },
            {
              value: "纸质",
              label: "纸质"
            }
          ]
        }
      ],
      fq: false,
      bz: false,
      yj:false
    };
  },
  created() {
    this.getorder();
    this.getcp();
    let data1 = JSON.parse(localStorage.getItem("enterpristList"));
    this.makeman = data1.username;
  },
  methods: {
    //订单类型数据
    getorder() {
      axios("apis/SalesManagement.asmx/SaleXl?index=1").then(({ data }) => {
        let data1 = this.$x2js.xml2js(data);
        let data3 = JSON.parse(data1.string.__text);
        console.log(data3);
        this.ordtypevalue = data3;
      });
    },
    //产品代码数据
    getcp() {
      axios("apis/SalesManagement.asmx/SaleXl?index=2").then(({ data }) => {
        let data1 = this.$x2js.xml2js(data);
        let data3 = JSON.parse(data1.string.__text);
        console.log(data3);
        this.procodevalue = data3;
      });
    },
    //新增订单
    addordre() {
      var val = [];
      for (var i = 0; i < this.tableData.length; i++) {
        this.tableData[i].deliverydate =
          this.tableData[i].deliverydate.getFullYear() +
          "-" +
          (this.tableData[i].deliverydate.getMonth() + 1) +
          "-" +
          this.tableData[i].deliverydate.getDate() +
          " ";
        if (this.tableData[i].protype !== undefined) {
          val.push(this.tableData[i]);
        }
      }

      let arr = {
        orderno: this.orderno,
        ordtype: this.ordtype,
        compony: this.compony,
        getorderdate:
          this.getorderdate.getFullYear() +
          "-" +
          (this.getorderdate.getMonth() + 1) +
          "-" +
          this.getorderdate.getDate() +
          " ",
        deliverydate:
          this.deliverydate.getFullYear() +
          "-" +
          (this.deliverydate.getMonth() + 1) +
          "-" +
          this.deliverydate.getDate() +
          " ",
        writer: this.writer,
        lstpro: val,
        hetongmoney: this.hetongmoney,
        paystyle: this.paystyle,
        payforstyle: this.payforstyle,
        lstpic: [this.imageUrl, this.imageUrl1, this.imageUrl2],
        makeman: this.makeman
      };
      let arr1 = JSON.stringify(arr);
      axios("apis/SalesManagement.asmx/OrdmanPK?index=3&jsondata=" + arr1).then(
        ({ data }) => {
          let data1 = this.$x2js.xml2js(data);
          let data3 = data1.string.__text;
          console.log(data3);
          if (data3 == "新增成功") {
            this.$message({
              message: "新增成功",
              type: "success"
            });
            this.$router.go(-1);
          } else {
            this.$message.error("新增失败");
          }
        }
      );
    },
    //返回
    revert() {
      this.$router.go(-1);
    },
    //付款方式事件
    fkfs(e) {
      console.log(e);
      if (e == "分期") {
        this.fq = true;
        this.bz = false;
        this.yj = false;
      } else if (e == "全款") {
        this.fq = false;
        this.bz = false;
        this.yj = false;
      } else if (e == "特殊") {
        this.bz = true;
        this.fq = false;
        this.yj = false;
      } else if (e == "月结") {
        this.yj = true;
        this.bz = false;
        this.fq = false;
      }
    },
    //支付方式事件
    handleChange(value) {
      console.log(value);
    },
    //定金时间转换
    djfkdatefn() {
      this.djfkdate =
        this.djfkdate.getFullYear() +
        "-" +
        (this.djfkdate.getMonth() + 1) +
        "-" +
        this.djfkdate.getDate() +
        " ";
    },
    //尾款时间转换
    wkfkdatefn() {
      this.wkfkdate =
        this.wkfkdate.getFullYear() +
        "-" +
        (this.wkfkdate.getMonth() + 1) +
        "-" +
        this.wkfkdate.getDate() +
        " ";
    },
    //新增订单信息
    add4() {
      let arr = {};
      this.tableData.push(arr);
    },
    //删除订单信息
    del4(index) {
      this.tableData.splice(this.tableData[index], 1);
    },
    handleAvatarSuccess(res, file) {
      var datas = this.$x2js.xml2js(res);
      this.imageUrl = datas.UpFileReturn.url;
      this.imageUrls = datas.UpFileReturn.fullurl;
      console.log(this.imageUrl);
    },
    handleAvatarSuccess1(res, file) {
      var datas = this.$x2js.xml2js(res);
      this.imageUrl1 = datas.UpFileReturn.url;
      this.imageUrls1 = datas.UpFileReturn.fullurl;
      console.log(this.imageUrl1);
    },
    handleAvatarSuccess2(res, file) {
      var datas = this.$x2js.xml2js(res);
      this.imageUrl2 = datas.UpFileReturn.url;
      this.imageUrls2 = datas.UpFileReturn.fullurl;
      console.log(this.imageUrl2);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === "image/jpeg";
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error("上传头像图片只能是 JPG 格式!");
      }
      if (!isLt2M) {
        this.$message.error("上传头像图片大小不能超过 2MB!");
      }
      return isJPG && isLt2M;
    }
  }
};
</script>
<style lang="scss" scoped>
@import "@/assets/scss/base.scss";
.nav {
  height: 60px;
  padding: 0 1%;
  position: relative;
  p {
    height: 40px;
    margin: 10px 0;
    line-height: 40px;
    span {
      background: $Header_color;
      color: $Header_color;
    }
  }
  #nav_go5 {
    position: absolute;
    top: 10px;
    right: 1%;
    img {
      height: 16px;
      padding-right: 10px;
    }
  }
}
.step {
  width: 50%;
  position: absolute;
  top: 0;
  left: 25%;
}
.conter_box1 {
  background: $white;
  height: 150px;
  width: 98%;
  padding: 5px 1% 0 1%;

  p {
    height: 40px;
    em {
      display: inline-block;
      width: 25px;
      height: 25px;
      text-align: center;
      line-height: 25px;
      border-radius: 50% 50%;
      border: solid 1px #ccc;
    }
  }
  ul {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    color: #909399;
    li {
      width: 33%;
      font-size: 14px;
      margin-bottom: 10px;
      text-align: center;
    }
  }
}
.conter_box2 {
  background: $white;
  height: 100px;
  width: 98%;
  margin-top: 10px;
  padding: 5px 1% 0 1%;
  p {
    height: 40px;
    em {
      display: inline-block;
      width: 25px;
      height: 25px;
      text-align: center;
      line-height: 25px;
      border-radius: 50% 50%;
      border: solid 1px #ccc;
    }
  }
  ul {
    width: 100%;
    display: flex;
    color: #909399;
    li {
      width: 20%;
      font-size: 14px;
      margin-bottom: 10px;
    }
  }
}
.conter_box3 {
  background: $white;
  // height: 160px;
  width: 98%;
  margin-top: 10px;
  padding: 5px 1% 0 1%;
  p {
    height: 40px;
    em {
      display: inline-block;
      width: 25px;
      height: 25px;
      text-align: center;
      line-height: 25px;
      border-radius: 50% 50%;
      border: solid 1px #ccc;
    }
  }
}
.conter_box4 {
  background: $white;
  // height: 90px;
  width: 98%;
  margin-top: 10px;
  padding: 5px 1% 0 1%;
  p {
    height: 40px;

    em {
      display: inline-block;
      width: 25px;
      height: 25px;
      text-align: center;
      line-height: 25px;
      border-radius: 50% 50%;
      border: solid 1px #ccc;
    }
  }
  ul {
    width: 100%;
    overflow: hidden;
    color: #909399;
    // margin-right: 1%
    li {
      width: 33%;
      float: left;
      font-size: 14px;
      margin-bottom: 10px;
      text-align: right;
      p {
        text-align: left;
      }
    }
  }
}
#conter_box5 {
  background: $white;
  height: 200px;
  width: 98%;
  margin-top: 10px;
  padding: 5px 1% 0 1%;

  p {
    height: 40px;
    em {
      display: inline-block;
      width: 25px;
      height: 25px;
      text-align: center;
      line-height: 25px;
      border-radius: 50% 50%;
      border: solid 1px #ccc;
    }
  }
  ul {
    width: 100%;
    // display: flex;
    height: 130px;
    color: #909399;
    overflow: hidden;
    li {
      width: 33%;
      float: left;
      //font-size: 14px;
      height: 130px;
      margin-bottom: 10px;
      text-align: center;
      //   border: solid 1px red;
    }
  }
}
.dispose_box1 {
  border: solid 1px #ccc;
}
.dispose_box2,
.dispose_box3 {
  border: solid 1px #ccc;
  margin-top: 10px;
}
.bottom {
  text-align: center;
  padding-top: 10px;
  padding-bottom: 10px;
  // background: $white;
  //position: relative;
  p {
    width: 20%;
    // height: 50px;
    line-height: 40px;
    // position: absolute;
    // top: 30px;
    // left: 1%;
    // display: flex;
    //justify-content: space-between;
  }
}
</style>
<style>
.el-step__title {
  font-size: 14px;
}
.el-input__inner {
  font-size: 12px;
  /* color: rgb(192, 196, 204); */
}
#conter_box5 .avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
#conter_box5 .avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
#conter_box5 .avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 80px;
  height: 80px;
  line-height: 80px;
  text-align: center;
}
#conter_box5 .avatar {
  width: 80px;
  height: 80px;
  display: block;
}
</style>